package com.gg.redisbootservice.client;

import com.gg.redisbootservice.enums.RedisTemPlateEnum;
import com.gg.redisbootservice.handler.RedisTemplateHandler;
import com.gg.redisbootservice.service.RedisHashService;
import com.gg.redisbootservice.service.RedisHllService;
import com.gg.redisbootservice.service.RedisKeyService;
import com.gg.redisbootservice.service.RedisListService;
import com.gg.redisbootservice.service.RedisLockService;
import com.gg.redisbootservice.service.RedisSetService;
import com.gg.redisbootservice.service.RedisStringService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * redis 统一客户端
 *
 * @author gg
 * @version redisClient.java, v 0.1 2019-04-04 18:15 gg
 */
@Component
public class RedisClient {

    @Resource
    private RedisTemplateHandler redisTemplateHandler;


    /**
     * key 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisKeyService
     */
    public RedisKeyService key(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisKeyService(redisTemplate);
    }

    /**
     * String 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisStringService
     */
    public RedisStringService string(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisStringService(redisTemplate);
    }

    /**
     * List 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisListService
     */
    public RedisListService list(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisListService(redisTemplate);
    }

    /**
     * Hash 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisHashService
     */
    public RedisHashService hash(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisHashService(redisTemplate);
    }

    /**
     * set 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisSetService
     */
    public RedisSetService set(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisSetService(redisTemplate);
    }

    /**
     * lock 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisSetService
     */
    public RedisLockService lock(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisLockService(redisTemplate);
    }

    /**
     * hll 操作类型 工具类
     *
     * @param redisTemPlateEnum RedisTemPlateEnum
     * @return RedisSetService
     */
    public RedisHllService hll(RedisTemPlateEnum redisTemPlateEnum) {
        RedisTemplate<String, Object> redisTemplate = redisTemplateHandler.handler(redisTemPlateEnum);
        return new RedisHllService(redisTemplate);
    }

}